package com.yang.designmode.ActionMode.observer;

import java.util.ArrayList;
import java.util.List;
// 实现具体的被观察者
public class ConcreteSubject implements Subject {
    private List<Observer> observers = new ArrayList<>();

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers(String message) {
        for (Observer observer : observers) {
            observer.update(message);
        }
    }

    // 模拟状态变化并通知观察者
    public void someBusinessLogic() {
        System.out.println("Subject: 发生了某些业务逻辑变化");
        notifyObservers("状态已更新！");
    }
}

